package com.geekca.d8.work;

import java.util.Scanner;

public class CountAlphaNum {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串: ");
        String str = scanner.next();
        CountStr(str);
    }

    public static void CountStr(String str) {
        char[] charList = str.toCharArray();
        int alphaCount = 0; // 字母计数器
        int numCount = 0;   // 数字计数器
        for (int i = 0; i < charList.length; i++) {
            int charVar = Integer.valueOf(charList[i]);
            if ((charVar >= 65 && charVar <= 90) || (charVar >= 97 && charVar <= 122)) {
                alphaCount += 1;
            } else if (charVar >= 48 && charVar <= 57) {
                numCount += 1;
            } else {
                System.out.println(charList[i] + " 为非字母或数字");
            }
        }
        System.out.println("字符串含有 " + alphaCount + "个字母" + numCount + "数字");
    }
}
